<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>layui</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="/layui/lib/layui-v2.6.3/css/layui.css" media="all">
    <link rel="stylesheet" href="/layui/css/public.css" media="all">
</head>
<style>
    .layui-table-cell {
        height: auto;
        height: auto!important;
        white-space: normal;
        text-align: center;
    }
</style>
<body>
<div class="layuimini-container">
    <div class="layuimini-main">
        <input name="id" value="${id}" type="hidden">
        <fieldset class="table-search-fieldset">

        </fieldset>

        <script type="text/html" id="toolbarDemo">

        </script>

        <table class="layui-hide" id="currentTableId" lay-filter="currentTableFilter"></table>

        <script type="text/html" id="currentTableBar">
            {{#  if(d.status== "2"){ }}
            <%--            <c:if test="status=='2'||status=='4'||status =='3'">--%>
            <a class="layui-btn layui-btn-normal layui-btn-xs data-count-edit" lay-event="yes2">同意投放</a>
            <a class="layui-btn layui-btn-normal layui-btn-xs data-count-edit" lay-event="no2">拒绝</a>
            <%--            </c:if>--%>
            {{#  } }}
            <%--            {{#  if(d.status == "3" && d.order.status == "1" ){ }}--%>
            <%--                    <a class="layui-btn layui-btn-normal layui-btn-xs data-count-edit" lay-event="success">完成</a>--%>
            <%--            {{#  } }}--%>
        </script>

    </div>
</div>
<script src="/layui/lib/layui-v2.6.3/layui.js" charset="utf-8"></script>
<script>
    layui.use(['form', 'table'], function () {
        var $ = layui.jquery,
            form = layui.form,
            table = layui.table;

        table.render({
            elem: '#currentTableId',
            url: '/user/list',
            method: 'post',
            toolbar: '#toolbarDemo',
            defaultToolbar: ['filter', 'exports', 'print', {
                title: '提示',
                layEvent: 'LAYTABLE_TIPS',
                icon: 'layui-icon-tips'
            }],
            cols: [[
                {type: "checkbox", width: 50},
                {field: 'id', title: 'ID', sort: true},
                {field: 'theme', title: '主题'},
                {field: 'brand', title: '品牌'},
                {field: 'compUrl', title: '公司链接',templet: '#compUrl'},
                {templet:'<div>{{d.classify.name}}</div>', title: '所属行业'},
                {field: 'productUrl', title: '产品详情链接',templet: '#product'},
                {field: 'detail', title: '推广需求详情'},
                {field: 'proof', title: '资质证明',templet: '#imgTpl'},
                {templet:'<div>{{d.advertiser.username}}</div>', title: '广告主'},
                {title: '状态', templet: function (res) {
                        if (res.status == '1') {
                            return '<a class="layui-btn layui-btn-xs layui-btn-danger data-count-delete">自媒体审核</a>';
                        } else if (res.status == '2') {
                            return '<a class="layui-btn layui-btn-xs layui-btn-danger data-count-delete">平台审核</a>';
                        } else if (res.status == '3'){
                            return '<a class="layui-btn layui-btn-xs layui-btn-danger data-count-delete">投放完成</a>';
                        }else if (res.status == '4'){
                            return '<a class="layui-btn layui-btn-xs layui-btn-danger data-count-delete">正在投放中</a>';
                        }else if (res.status == '5'){
                            return '<a class="layui-btn layui-btn-xs layui-btn-danger data-count-delete">媒体主未通过</a>';
                        }else if (res.status == '6'){
                            return '<a class="layui-btn layui-btn-xs layui-btn-danger data-count-delete">管理员审核未通过</a>';
                        }else if (res.status == '7'){
                            return '<a class="layui-btn layui-btn-xs layui-btn-danger data-count-delete">广告主拒绝验收</a>';
                        }else if (res.status == '8'){
                            return '<a class="layui-btn layui-btn-xs layui-btn-danger data-count-delete">广告主已完成验收</a>';
                        }
                    }},
                {title: '操作', minWidth: 150, toolbar: '#currentTableBar', align: "center"}
            ]],
            limits: [10, 20, 30, 50, 100],
            limit: 10,
            page: true,
            request: {
                pageName: 'pageNum',
                limitName: 'pageSize'
            }
        });

        // 监听搜索操作
        form.on('submit(data-search-btn)', function (data) {
            /*var result = JSON.stringify(data.field);
            layer.alert(result, {
                title: '最终的搜索信息'
            });*/

            //执行搜索重载
            table.reload('currentTableId', {
                page: {
                    curr: 1
                }
                , where: data.field
            }, 'data');

            return false;
        });

        //监听表格复选框选择
        table.on('checkbox(currentTableFilter)', function (obj) {
            console.log(obj)
        });

        /**
         * toolbar监听事件
         */
        table.on('toolbar(currentTableFilter)', function (obj) {
            if (obj.event === 'add') {  // 监听添加操作
                var index = layer.open({
                    title: '添加管理员',
                    type: 2,
                    shade: 0.2,
                    maxmin:true,
                    shadeClose: true,
                    area: ['100%', '100%'],
                    content: '/user/add',
                });
                $(window).on("resize", function () {
                    layer.full(index);
                });
            } else if (obj.event === 'delete') {  // 监听删除操作
                var checkStatus = table.checkStatus('currentTableId')
                    , data = checkStatus.data;
                // layer.alert(JSON.stringify(data));

                if (data.length == 0) {
                    layer.msg('未选择数据');
                    return;
                }

                layer.confirm('是否确认删除？', function () {
                    var ids = new Array();
                    $.each(data, function (index, element) {
                        ids.push(element.id);
                    });

                    $.ajax({
                        url: '/user/delete',
                        type: 'post',
                        data: "id=" + ids,
                        dataType: 'json',
                        success: function (result) {
                            if (result.code == '0') {
                                // 重新加载表格数据
                                table.reload('currentTableId', {
                                    page: {
                                        curr: 1
                                    }
                                }, 'data');
                                layer.msg('删除成功');
                            }
                        }
                    });
                });
            }
        });

        //监听表格复选框选择
        table.on('checkbox(currentTableFilter)', function (obj) {
            console.log(obj)
        });

        table.on('tool(currentTableFilter)', function (obj) {
            var data = obj.data;
            if (obj.event === '') {
                var index = layer.open({
                    title: '上传凭证',
                    type: 2,
                    shade: 0.2,
                    maxmin:true,
                    shadeClose: true,
                    area: ['50%', '60%'],
                    content: '/resource/success?id=' + data.order.id,
                });
                $(window).on("resize", function () {
                    layer.full(index);
                });
                return false;
            } else if (obj.event === 'yes2') {
                layer.confirm('确认通过？', function (index) {
                    $.ajax({
                        url: '/user/yes2',
                        type: 'post',
                        data: "id=" + data.id,
                        dataType: 'json',
                        success: function (result) {
                            if (result.code == '0') {
                                // 重新加载表格数据
                                table.reload('currentTableId', {
                                    page: {
                                        curr: 1
                                    }
                                }, 'data');
                                layer.msg('已同意');
                            }
                        }
                    });
                });
            }else if (obj.event === 'success') {
                layer.confirm('确认完成吗', function (index) {
                    $.ajax({
                        url: '/resource/success',
                        type: 'post',
                        data: "id=" + data.order.id,
                        dataType: 'json',
                        success: function (result) {
                            if (result.code == '0') {
                                // 重新加载表格数据
                                table.reload('currentTableId', {
                                    page: {
                                        curr: 1
                                    }
                                }, 'data');
                                layer.msg('已完成');
                            }
                        }
                    });
                });
            }else if (obj.event === 'no2') {
                layer.confirm('真的拒绝吗', function (index) {
                    $.ajax({
                        url: '/user/no2',
                        type: 'post',
                        data: "id=" + data.id,
                        dataType: 'json',
                        success: function (result) {
                            if (result.code == '0') {
                                // 重新加载表格数据
                                table.reload('currentTableId', {
                                    page: {
                                        curr: 1
                                    }
                                }, 'data');
                                layer.msg('已拒绝');
                            }
                        }
                    });
                    /*
                    obj.del();
                    layer.close(index);*/
                });
            }else if (obj.event === 'editRole') {

                var index = layer.open({
                    title: '编辑管理员',
                    type: 2,
                    shade: 0.2,
                    maxmin:true,
                    shadeClose: true,
                    area: ['100%', '100%'],
                    content: '/admin/editRole?id=' + data.id,
                });
                $(window).on("resize", function () {
                    layer.full(index);
                });
                return false;
            }
        });

    });
</script>
<style>
    .layui-table-cell {
        height: auto;
        height: auto!important;
        white-space: normal;
        text-align: center;
    }
</style>
<script type="text/html" id="imgTpl">
    <img src="{{ d.proof }}">
</script>

<script type="text/html" id="compUrl">
    <a href="{{ d.compUrl }}" target="_blank">立即访问</a>
</script>
<script type="text/html" id="product">
    <a href="{{ d.productUrl }}">立即访问</a>
</script>
</body>
</html>
